﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class RegistrationType : IEquatable<RegistrationType>
    {
        public void ImportList(List<Classes.RegistrationType> RegTList)
        {
            var mdb = new MedregDBDataContext();
            var ListRegT = new List<RegistrationType>();
            foreach (var regT in RegTList)
            {
                RegistrationType regT1 = new RegistrationType() { ID = regT.ID, Name = regT.Name };
                RegistrationType query;

                if (mdb.RegistrationType.LongCount() == 0)
                {
                    mdb.RegistrationType.InsertOnSubmit(regT1);
                }
                else
                {
                    try
                    {
                        query = mdb.RegistrationType.Single(l => l.ID == regT1.ID);
                        query.Name = regT1.Name;

                    }
                    catch (ArgumentNullException e)
                    {
                    }
                    catch (InvalidOperationException e)
                    {

                        if (!ListRegT.Contains(regT1))
                        {
                            mdb.RegistrationType.InsertOnSubmit(regT1);
                            ListRegT.Add(regT1);
                        }
                    }
                }
            }
            mdb.SubmitChanges();
        }
        public bool Equals(RegistrationType other)
        {
            var i = this.ID.Equals(other.ID);
            var j = this.Name.Equals(other.Name);
            if (i & j)
            {
                return true;
            }
            return false;
        }
    }
}
